//
//  UIImage+Extension.swift
//  Demo-04-TabBarTest
//
//  Created by 苏统世 on 16/5/25.
//  Copyright © 2016年 SuTon. All rights reserved.
//

import UIKit

extension UIImage {
    
    /// 拉伸平铺按钮
    class func getResizableImageWithString(imageName:String) -> UIImage {
        return UIImage(named: imageName)!.resizableImageWithCapInsets(UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1), resizingMode: UIImageResizingMode.Stretch)
    }
    
    /// 画圆图片，带边框
    class func getCircleImageWithSourceImage(image:UIImage,borderWidth border:CGFloat,borderColor color:UIColor)->UIImage{
        let width = image.size.width + border
        let height = image.size.height + border
        UIGraphicsBeginImageContext(CGSize(width: width, height: height))
        //画圆
        CGContextAddArc(UIGraphicsGetCurrentContext(), width*0.5, height*0.5, min(width, height)*0.5, 0, CGFloat(M_PI)*2.0, 0)
        //填充
        color.setFill()
        //画内圆
        CGContextAddArc(UIGraphicsGetCurrentContext(), width*0.5, height*0.5, min(width, height) - border, 0, CGFloat(M_PI)*2.0, 0)
        CGContextClip(UIGraphicsGetCurrentContext())
        
        image.drawInRect(CGRect(x: border, y: border, width: image.size.width, height: image.size.height), blendMode: CGBlendMode.Hue, alpha: 0.8)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage
    }
}

